﻿using Inovout.Business;
using System.Windows.Input;
using Inovout.Gui.Wpf.Commands;
using Inovout.Gui.Wpf;
using Inovout.Portal.Desktop.Workbenchs;

namespace Inovout.Portal.Desktop
{
    public class WorkbenchCommand : ViewModelCommand
    {
        private BaseWorkbenchViewModel workbenchViewModel;
        public WorkbenchCommand(BaseWorkbenchViewModel workbenchViewModel, Function function)
            : base(function)
        {
            this.workbenchViewModel = workbenchViewModel;
        }

        public override bool CanExecute(object parameter)
        {
            ICommand command = ViewModelCommandManager.GetCommand(workbenchViewModel.ActivedWorkspace,function); // workbenchViewModel.GetCommand(function);
            //if (command == null)
            //{
            //    return function.DependentFunction == null
            //      | workbenchViewModel.GetCommand(function.DependentFunction) != null;
            //}
            //else
            //{
            //    return command.CanExecute(parameter);
            //}
            return true;
        }

        public override void Execute(object parameter)
        {
            ICommand command = ViewModelCommandManager.GetCommand(workbenchViewModel.ActivedWorkspace, function); // workbenchViewModel.GetCommand(function);
            if (command == null)
            {
                base.Execute(parameter);
            }
            else
            {
                command.Execute(parameter);
            }
        }
    }
}
